<template>
  <div>
    <div class="tabs">
      <div
        v-for="(tab, index) in tabs"
        :key="index"
        @click="selectTab(index)"
        :class="{ active: selectedIndex === index }"
      >
        {{ tab.title }}
        <div class="underline" v-if="selectedIndex === index"></div>
      </div>
    </div>
    <!-- 内容区域根据选中的选项卡显示不同内容 -->
    <div class="content">{{ tabs[selectedIndex].content }}</div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      selectedIndex: 0, // 默认选中第一个选项卡
      tabs: [
        { title: "Tab 1", content: "内容 1" },
        { title: "Tab 2", content: "内容 2" },
        { title: "Tab 3", content: "内容 3" },
        // 添加更多选项卡
      ],
    };
  },
  methods: {
    selectTab(index) {
      this.selectedIndex = index;
    },
  },
};
</script>
<style>
.tabs {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tabs > div {
  cursor: pointer;
  padding: 10px;
  position: relative;
  transition: color 0.3s;
}

.tabs > div.active {
  color: blue; /* 选中时文字颜色为蓝色 */
}

.underline {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background-color: blue; /* 蓝色横线 */
  transform: scaleX(0); /* 初始状态下横线不可见 */
  transform-origin: left;
  transition: transform 0.3s;
}

.tabs > div.active .underline {
  transform: scaleX(1); /* 选中时显示横线 */
}
</style>